package com.admin.service;

import com.admin.bean.ApplyRefuse;
import com.admin.dbdao.DeveloperApplyDao;
import com.data.bean.RegistMassage;
import com.data.util.CheckDataUtils;
import com.data.util.DatabaseIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 开发者管理
 *
 * @author:HingLo
 * @create 2017-09-13 15:12
 **/
@Service
public class DeveloperApplyService {
    @Autowired
    private DeveloperApplyDao developerApplyDao;


    public List<?> findAllDeveloperApplyService(int type) {
        return developerApplyDao.findAllDeveloperApplyDao(type);
    }

    public byte[] lookIconService(String id) {
        id = id.trim();
        RegistMassage registMassage = developerApplyDao.lookIconDao(id);
        if (registMassage != null) {
            return registMassage.getNumpicture();
        }
        return null;
    }

    /**
     * 通过或者拒绝申请
     *
     * @param type
     * @param id
     * @return
     */
    public boolean passApplyService(int type, String id) {

        //检测id是否有效
        if (CheckDataUtils.stringUtilsID(id)) {
            id = id.trim();
            return developerApplyDao.updateApplyDao(type, id);
        }
        return false;
    }

    /**
     * 拒绝通过邮箱
     *
     * @param id
     * @param content
     * @return
     */
    public boolean refuseApplyService(String id, String content, String email) {
        id = id.trim();
        content = content.trim();
        if (developerApplyDao.updateApplyDao(id)) {
            ApplyRefuse applyRefuse = new ApplyRefuse();
            applyRefuse.setContent(content);
            applyRefuse.setCtime(new Date());
            applyRefuse.setId(DatabaseIdUtils.getDataIdOne());
            applyRefuse.setUid(id);
            if (developerApplyDao.refuseApplyDao(applyRefuse)) {
                //TODO:发送邮箱，提示账号申请没有通过。
//                String email = developerApplyDao.getEmailApplyDao(id);
//                boolean bool = SendMailUtils.sendMailMassage(email);
                return true;

            } else {
                return false;
            }
        } else {
            return false;
        }


    }

    public List<?> applyRefuseService() {
        return developerApplyDao.applyRefuseDao();
    }

    /**
     * 删除未通过的具体某个列表
     *
     * @param id
     * @return
     */
    public boolean deleteApplyService(String id) {
        id = id.trim();
        return developerApplyDao.deleteApplyDao(id);
    }
}
